<template>
  <div class="all">
    <header>
      <div class="div" @click="back">
        <img src="../../../../assets/返回.png" alt="">
        <span class="solid">返回</span>
      </div>
      <div class="div">
        <span>选择审批人</span>
      </div>
      <div class="div">
        <span></span>
      </div>
    </header>
    <van-radio-group v-model="radio" style="min-height: calc(100vh - 154px)">
    <van-cell-group>
      <van-cell
        v-for="(item, index) in teamList.doctor"
        clickable
        :key="item"
        :title="item.NICK_NAME"
        @click="radio = item"
      >
        <template #icon>
          <img v-if="item.PHOTO" class="photo" :src="item.PHOTO" alt="">
          <img v-else class="photo" src="../../../../assets/photo.png" alt="">
        </template>
        <template #right-icon>
          <van-radio :name="item" />
        </template>
      </van-cell>
    </van-cell-group>
    </van-radio-group>
    <div class="keepDiv">
      <button class="keepBtn" @click="keep">保存</button>
    </div>
  </div>
</template>

<script>
import {Toast} from 'vant'
export default {
  name: 'SelectExaminer',
  data () {
    return {
      team_id: this.$route.query.team_id,
      userid: this.$route.query.userid,
      teamList: [],
      radio: ''
    }
  },
  mounted () {
    this.getTeamList()
  },
  methods: {
    // 保存
    keep () {
      // if (this.radio) {
      let data = JSON.parse(sessionStorage.getItem('JuageData'))
      let isrepeat = false
      data.list.map((curr, index) => {
        if (curr.doc_user_id) {
          if (curr.doc_user_id == this.radio.USER_ID) {
            isrepeat = true
            return false
          }
        }
      })
      if (isrepeat === true) {
        Toast('审批人重复')
        // return false
      }
      data.list[data.index].doc_user_id = this.radio.USER_ID
      data.list[data.index].value = this.radio.NICK_NAME
      sessionStorage.setItem('JuageData', JSON.stringify(data))
      this.back()
    },
    getTeamList () {
      this.$http.Teamdetail({id: this.team_id})
        .then(res => {
          console.log(res)
          if (res.data.status === 'success') {
            this.teamList = res.data.data
            let data = JSON.parse(sessionStorage.getItem('JuageData'))
            this.teamList.doctor.map((curr, index) => {
              if (curr.USER_ID == data.list[data.index].doc_user_id) {
                this.radio = curr
              }
            })
          } else {
            Toast(res.data.msg)
          }
        })
        .catch(err => {
          console.log(err)
          Toast('您的网络有些拥挤，请稍后再试')
        })
    },
    // 返回
    back () {
      this.$router.history.go(-1)
    }
  }
}
</script>

<style scoped>
.all{
  width: 100%;
  height: 100%;
  background: #FAF9FE;
  overflow: auto;
  font-size: 15px;
  font-family: PingFang SC;
}
header{
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #E5E5E5;
  background: white;
  position: sticky;
  top: 0;
  z-index: 9;
}
.div{
  width: 33%;
  height: 100%;
  display: flex;
  align-items: center;
  font-family: "PingFang SC";
  font-size: 15px;
  font-weight: bold;
}
.div img{
  margin-right: 5px;
}
.div:nth-child(1) img{
  height: 13px;
  width: 7px;
  margin-left: 15px;
}
.div:nth-child(3) img{
  margin-right: 5px;
  width: 13px;
  height: 13px;
}
.div:nth-child(3) span{
  margin-right: 15px;
}
.div:nth-child(2){
  justify-content: center;
}
.div:nth-child(3){
  justify-content: flex-end;
}
.solid{
  color: #1DA4F2;
}
.photo{
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}
/deep/ .van-cell__title, .van-cell__value {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  display: flex;
  align-items: center;
}
.keepDiv{
  width: 100%;
  height: 60px;
  background: #FFFFFF;
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.keepBtn{
  width: 90%;
  height: 44px;
  border-radius: 20px;
  border: none;
  font-size: 17px;
  font-family: PingFang SC;
  font-weight: bold;
  color: #FFFFFF;
  background: linear-gradient(90deg, #1DA3F2 0%, #1DC7F2 100%);
}
</style>
